package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.po.User;
import org.apache.ibatis.annotations.*;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    
    /**
     * 获取用户年龄分布统计
     */
    @Select("SELECT " +
           "CASE " +
           "    WHEN age < 18 THEN '18岁以下' " +
           "    WHEN age BETWEEN 18 AND 24 THEN '18-24岁' " +
           "    WHEN age BETWEEN 25 AND 34 THEN '25-34岁' " +
           "    WHEN age BETWEEN 35 AND 44 THEN '35-44岁' " +
           "    ELSE '45岁以上' " +
           "END as name, " +
           "COUNT(*) as value " +
           "FROM users " +
           "GROUP BY " +
           "CASE " +
           "    WHEN age < 18 THEN '18岁以下' " +
           "    WHEN age BETWEEN 18 AND 24 THEN '18-24岁' " +
           "    WHEN age BETWEEN 25 AND 34 THEN '25-34岁' " +
           "    WHEN age BETWEEN 35 AND 44 THEN '35-44岁' " +
           "    ELSE '45岁以上' " +
           "END " +
           "ORDER BY " +
           "CASE name " +
           "    WHEN '18岁以下' THEN 1 " +
           "    WHEN '18-24岁' THEN 2 " +
           "    WHEN '25-34岁' THEN 3 " +
           "    WHEN '35-44岁' THEN 4 " +
           "    ELSE 5 " +
           "END")
    List<Map<String, Object>> getAgeDistribution();
} 